<?php
/**
 * 把区域多维数组转成二维数组
 * @return string
 */
function getAreaArr($ares, $arr = []){
    foreach ($ares as $v) {
        if ($v['areatype'] == 2) {
        	$v_arr['id'] = $v['id'];
            $v_arr['tag'] = $v['tag'];
        	$v_arr['areaname'] = $v['areaname'];
            $arr[] = $v_arr;
        }
        if ($v['child']) {
            foreach ($v['child'] as $vv) {
                if ($vv['areatype'] == 2) {
                	$vv_arr['id'] = $vv['id'];
                    $vv_arr['tag'] = $vv['tag'];
                	$vv_arr['areaname'] = $v['areaname'].' '.$vv['areaname'];
                    $arr[] = $vv_arr;
                }
                if ($vv['child']) {
                    foreach ($vv['child'] as $vvv) {
		                if ($vvv['areatype'] == 2) {
                            $vvv_arr['id'] = $vvv['id'];
		                	$vvv_arr['tag'] = $vvv['tag'];
		                	$vvv_arr['areaname'] = $v['areaname'].' '.$vv['areaname'].' '.$vvv['areaname'];
		                    $arr[] = $vvv_arr;
		                }
                        if ($vvv['child']) {
                            foreach ($vvv['child'] as $vvvv) {
				                if ($vvvv['areatype'] == 2) {
                                    $vvvv_arr['id'] = $vvvv['id'];
				                	$vvvv_arr['tag'] = $vvvv['tag'];
				                	$vvvv_arr['areaname'] = $v['areaname'].' '.$vv['areaname'].' '.$vvv['areaname'].' '.$vvvv['areaname'];
				                    $arr[] = $vvvv_arr;
				                }
                                if ($vvvv['child']) {
                                    foreach ($vvvv['child'] as $vvvvv) {
						                if ($vvvv['areatype'] == 2) {
                                            $vvvvv_arr['id'] = $vvvvv['id'];
						                	$vvvvv_arr['tag'] = $vvvvv['tag'];
						                	$vvvvv_arr['areaname'] = $v['areaname'].' '.$vv['areaname'].' '.$vvv['areaname'].' '.$vvvv['areaname'].' '.$vvvvv['areaname'];
						                    $arr[] = $vvvvv_arr;
						                }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $arr;
}
//合并有交集的数组
function getWeekTime($weekArr){
    $opentime = [];
    if ($weekArr[0]['endtime'] >= $weekArr[1]['starttime']) {
        if ($weekArr[1]['endtime'] >= $weekArr[2]['starttime']) {
            $opentime[] = ['starttime'=>$weekArr[0]['starttime'],'endtime'=>$weekArr[2]['endtime']];
        }else{
            $opentime[] = ['starttime'=>$weekArr[0]['starttime'],'endtime'=>$weekArr[1]['endtime']];
            $opentime[] = ['starttime'=>$weekArr[2]['starttime'],'endtime'=>$weekArr[2]['endtime']];
        }
    }else{
        if ($weekArr[1]['endtime'] >= $weekArr[2]['starttime']) {
            $opentime[] = ['starttime'=>$weekArr[0]['starttime'],'endtime'=>$weekArr[0]['endtime']];
            $opentime[] = ['starttime'=>$weekArr[1]['starttime'],'endtime'=>$weekArr[2]['endtime']]; 
        }else{
            $opentime[] = ['starttime'=>$weekArr[0]['starttime'],'endtime'=>$weekArr[0]['endtime']];
            $opentime[] = ['starttime'=>$weekArr[1]['starttime'],'endtime'=>$weekArr[1]['endtime']]; 
            $opentime[] = ['starttime'=>$weekArr[2]['starttime'],'endtime'=>$weekArr[2]['endtime']]; 
        }
    }
    return $opentime;
}
//数据返回格式
function show($code,$message,$arr=[]){
    $data['code'] = $code;
    $data['msg'] = $message;
    $data['data'] = $arr;
    return $data;
}
//使用curl 发送get/post请求 $fileds存在就是post请求
function curl($url,$fileds=[]){
    $ch = curl_init();
    //设置我们请求的地址
    curl_setopt($ch, CURLOPT_URL, $url);
    //数据返回不要直接显示
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    //禁止证书验证
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    if ($fileds) {
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fileds);
    }

    $data='';
    if (curl_exec($ch)) {
        //如果发送成功,获取数据
        $data=curl_multi_getcontent($ch);
    }
    curl_close($ch);
    return $data;
}